﻿Public Class fTipoGasto
    Dim daTipoGasto As lbGlobalcom.dsCajaTableAdapters.CAJ_TIPOGASTOTableAdapter
    Dim daClave As lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter

    Private Sub fTipoGasto_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If Me.DsCaja.CAJ_TIPOGASTO.GetChanges IsNot Nothing Then
                CAJ_TIPOGASTOBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    CAR_TIPOGASTOBindingNavigatorSaveItem.PerformClick()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub fTipoGasto_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        daTipoGasto = New lbGlobalcom.dsCajaTableAdapters.CAJ_TIPOGASTOTableAdapter
        daClave = New lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
    End Sub

    Private Sub btnCargaTipoGasto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCargaTipoGasto.Click
        Try
            If Me.DsCaja.CAJ_TIPOGASTO.GetChanges IsNot Nothing Then
                CAJ_TIPOGASTOBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    CAR_TIPOGASTOBindingNavigatorSaveItem.PerformClick()
                End If
            End If
            daTipoGasto.Fill(DsCaja.CAJ_TIPOGASTO)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Try
            If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                CAJ_TIPOGASTOBindingSource.RemoveCurrent()
                daTipoGasto.Update(DsCaja.CAJ_TIPOGASTO)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub CAJ_TIPOGASTOBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CAR_TIPOGASTOBindingNavigatorSaveItem.Click
        Try
            Validate()
            CAJ_TIPOGASTOBindingSource.EndEdit()
            daTipoGasto.Update(DsCaja.CAJ_TIPOGASTO)
            MessageBox.Show("Se salvarón registros con exito", "Salvar Registro", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub CAJ_TIPOGASTODataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles CAR_TIPOGASTODataGridView.CellBeginEdit
        Try
            If e.ColumnIndex = 1 AndAlso CAR_TIPOGASTODataGridView.Rows(e.RowIndex).Cells(0).Value Is DBNull.Value Then
                Dim dt As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASDataTable
                dt = daClave.GetDataByIdClavePrimaria("PRO_MARCAS")
                If dt.Count Then
                    Dim dr As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASRow
                    dr = dt.Rows(0)
                    Dim Cons As lbGlobalcom.ConsecTablas = New lbGlobalcom.ConsecTablas(dr("TABLA"), dr("CAMPO"), dr("LONGITUD"))
                    CAR_TIPOGASTODataGridView.Rows(e.RowIndex).Cells(0).Value = Cons.NumeroConsec
                    Cons = Nothing
                    daTipoGasto.Update(DsCaja.CAJ_TIPOGASTO)
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub CAJ_TIPOGASTODataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles CAR_TIPOGASTODataGridView.DataError
        MessageBox.Show(e.Exception.Message)
    End Sub

    Private Sub CAJ_TIPOGASTODataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles CAR_TIPOGASTODataGridView.UserDeletedRow
        Try
            daTipoGasto.Update(DsCaja.CAJ_TIPOGASTO)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub CAJ_TIPOGASTODataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles CAR_TIPOGASTODataGridView.UserDeletingRow
        If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub

End Class